﻿using ComTools.Config;
using ComTools.Helpers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Redis.Config
{
    /// <summary>
    /// 用于读取缓存的配置信息
    /// </summary>
    public class ConfigManager
    {
        /// <summary>
        /// 配置信息
        /// </summary>
        private static dynamic _cacheConfig;

        /// <summary>
        /// 数据库配置信息
        /// </summary>
        public static dynamic cacheConfig => _cacheConfig;


        /// <summary>
        /// 静态代码块，程序启动时初始化
        /// </summary>
        static ConfigManager()
        {
            try
            {
                using (StreamReader sr = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config\\redis.config.json")))
                {
                    _cacheConfig = new DynamicHelper();
                    _cacheConfig.success = true;
                    _cacheConfig.config = sr.ReadToEnd().JSONToObject<dynamic>();
                }
            }
            catch (Exception ex)
            {

                _cacheConfig = new DynamicHelper();
                _cacheConfig.success = false;
                _cacheConfig.ex = ex.Message;
            }
        }
    }
}
